package com.seocoo.worker.order.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.seocoo.worker.R;
import com.seocoo.worker.order.entity.RspOrderMaintain;
import com.seocoo.worker.order.widget.OrderDetailMaintanceAddressView;
import com.seocoo.worker.order.widget.rsp.RspOrderDetailAddress;

/**
 * author : Ssp
 * e-mail : 981297079@qq.com
 * date   : 2020/2/2320:32
 * desc   : 维修订单
 * version: 1.0
 */
public class OrderMaintainAdapter extends BaseQuickAdapter<RspOrderMaintain, BaseViewHolder> {

    private String takeType;

    public OrderMaintainAdapter() {
        super(R.layout.order_maintain_item);
    }

    @Override
    protected void convert(BaseViewHolder helper, RspOrderMaintain item) {
        helper.setText(R.id.tv_time, item.getAddTime());

        String expirationState = item.getExpirationState();
        if (TextUtils.equals("1", expirationState)) {
            expirationState = "商品质保中";
        } else if (TextUtils.equals("2", expirationState)) {
            expirationState = "商品已过期";
        } else {
            expirationState = "";
        }

        helper.setText(R.id.tv_cargo_state, expirationState);
        if (TextUtils.equals("1", item.getMaintainType())) {
            helper.setGone(R.id.tv_cargo_state, true);
        } else {
            helper.setGone(R.id.tv_cargo_state, false);
        }

        helper.setText(R.id.tv_order_type, takeType);
        initAddress(helper, item);
        initBottom(helper, item);

    }

    private void initAddress(BaseViewHolder helper, RspOrderMaintain item) {
        OrderDetailMaintanceAddressView view = helper.getView(R.id.order_detail_address_view);
        RspOrderDetailAddress address = new RspOrderDetailAddress();
        address.setUserAddress(item.getProvince() + item.getCity() + item.getDistrict() + item.getCommunity() + item.getDoorPlate());
        address.setUserName(item.getConsignee());
        address.setUserPhone(item.getContact());
        address.setMerchantContact(item.getMerchantContact());
        String maintainType;
        //维修单类型1-平台商品 2-其他商品
        if (TextUtils.equals("1", item.getMaintainType())) {
            maintainType = "平台商品";
        } else {
            maintainType = "其他商品";
        }
        address.setMaintainType(maintainType);
        view.initData(address);
    }

    private void initBottom(BaseViewHolder helper, RspOrderMaintain item) {
        TextView view = helper.getView(R.id.tv_order_receiving);
        helper.addOnClickListener(R.id.tv_order_receiving);
        String status = item.getOrderStatus();
        if (TextUtils.equals("1", status)) {
            view.setVisibility(View.VISIBLE);
        } else {
            view.setVisibility(View.GONE);
        }
    }

    public void setTakeType(String takeType1) {
        this.takeType = takeType1;
    }
}
